package com.allwees.bs.module.oms.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import com.allwees.bs.core.model.order.entity.OrderModel;
import com.allwees.bs.core.model.order.wf.order.EOrderAction;
import com.allwees.bs.core.model.order.wf.order.EOrderState;
import com.allwees.core.common.util.reflect.PojoUtil;
import com.allwees.core.wf.Workflow;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;

@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@TableName("o_order")
public class Order extends OrderModel implements Workflow<EOrderState, EOrderAction> {

    @Column(columnDefinition = "varchar(255)")
    @Enumerated(EnumType.STRING)
    protected EOrderAction latestAction;

    @Column(columnDefinition = "varchar(255)")
    @Enumerated(EnumType.STRING)
    protected EOrderState backState;

    @Column(columnDefinition = "varchar(255)")
    @Enumerated(EnumType.STRING)
    protected EOrderState state;

    @Override
    public String getBsKey() {
        return uuid;
    }

    @Override
    public EOrderState getState() {
        return state;
    }

    public String getStateDesc() {
       return state.customerDesc();
    }

    public OmsOrder convertToOmsOrder() {
        return PojoUtil.copyWithOmit(new OmsOrder(), this, "latestAction","backState","state");
    }
}
